using Castle.Core.Interceptor;
using IglooCoder.Commons.Logging;

namespace IglooCoder.Commons.AOP
{
    public class LoggingInterceptor : IInterceptor
    {
        private readonly IParseInputParameters _parameterParser;

        public LoggingInterceptor(IParseInputParameters parameterParser)
        {
            _parameterParser = parameterParser;
        }

        public void Intercept(IInvocation invocation)
        {
            Log.For(invocation.TargetType)
                .Info(string.Format("Input: {0}", 
                _parameterParser.On(invocation.Arguments)));

            invocation.Proceed();

            Log.For(invocation.TargetType)
                .Info(string.Format("Returned: {0}", 
                _parameterParser.On(new object[1] {invocation.ReturnValue})));
        }
    }
}